<!DOCTYPE html>
<html lang=zh>
<head>
  <meta charset="utf-8">
  <meta name=referrer content=never>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>Spring AOP @Before @Around @After 等 advice 的执行顺序 | JiSong‘s Blog</title>
  <meta name="description" content="author:rainbow702url:https://blog.csdn.net/rainbow702/article/details/52185827  用过spring框架进行开发的人，多多少少会使用过它的AOP功能，都知道有@Before、@Around和@After等advice。最近，为了实现项目中的输出日志和权限控制这两个需求，我也使用到了AOP功能。我使用到了@Before、@">
<meta name="keywords" content="Spring,AOP">
<meta property="og:type" content="article">
<meta property="og:title" content="Spring AOP @Before @Around @After 等 advice 的执行顺序">
<meta property="og:url" content="https://ji-song.gitee.io/blog/2018/07/05/Spring AOP @Before @Around @After 等 advice 的执行顺序/index.html">
<meta property="og:site_name" content="JiSong">
<meta property="og:description" content="author:rainbow702url:https://blog.csdn.net/rainbow702/article/details/52185827  用过spring框架进行开发的人，多多少少会使用过它的AOP功能，都知道有@Before、@Around和@After等advice。最近，为了实现项目中的输出日志和权限控制这两个需求，我也使用到了AOP功能。我使用到了@Before、@">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://pba56k9nr.bkt.clouddn.com/AOP%E9%A1%BA%E5%BA%8F%E6%AD%A3%E5%B8%B8%E6%83%85%E5%86%B5.png">
<meta property="og:image" content="http://pba56k9nr.bkt.clouddn.com/AOP%E9%A1%BA%E5%BA%8F%E5%BC%82%E5%B8%B8%E6%83%85%E5%86%B5.png">
<meta property="og:image" content="http://pba56k9nr.bkt.clouddn.com/AOP%E5%A4%9A%E5%88%87%E7%82%B9%E6%8B%A6%E6%88%AA%E9%A1%BA%E5%BA%8F.png">
<meta property="og:updated_time" content="2018-07-05T12:16:44.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Spring AOP @Before @Around @After 等 advice 的执行顺序">
<meta name="twitter:description" content="author:rainbow702url:https://blog.csdn.net/rainbow702/article/details/52185827  用过spring框架进行开发的人，多多少少会使用过它的AOP功能，都知道有@Before、@Around和@After等advice。最近，为了实现项目中的输出日志和权限控制这两个需求，我也使用到了AOP功能。我使用到了@Before、@">
<meta name="twitter:image" content="http://pba56k9nr.bkt.clouddn.com/AOP%E9%A1%BA%E5%BA%8F%E6%AD%A3%E5%B8%B8%E6%83%85%E5%86%B5.png">
  <!-- Canonical links -->
  <link rel="canonical" href="https://ji-song.gitee.io/blog/2018/07/05/Spring AOP @Before @Around @After 等 advice 的执行顺序/index.html">
  
    <link rel="alternate" href="/atom.xml" title="JiSong" type="application/atom+xml">
  
  
    <link rel="icon" href="/blog/favicon.png" type="image/x-icon">
  
  <!-- font-awesome CSS -->
  <!-- <link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> -->
  <link rel="stylesheet" href="/blog/css/style.css">
  
    
    

</head>


<body class="main-center theme-green" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://gitee.com/ji-song" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/avatar.jpeg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">JiSong</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">Java Coder</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> HangZhou, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav">
        
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">所有文章</span>
          </a>
        </li>
        
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://gitee.com/ji-song" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">了解一下</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验!来来来</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/技能/">技能</a><span class="category-list-count">19</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/生活/">生活</a><span class="category-list-count">2</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/AOP/">AOP</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/DB/">DB</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/JDK/">JDK</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/JVM/">JVM</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/Kotlin/">Kotlin</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/Log/">Log</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/MVC/">MVC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/Spring/">Spring</a><span class="tag-list-count">10</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/job/">job</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/kotlin/">kotlin</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/linux/">linux</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/plan/">plan</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/sublime/">sublime</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/事务/">事务</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/坑记/">坑记</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/并发/">并发</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/集合/">集合</a><span class="tag-list-count">2</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/blog/tags/AOP/" style="font-size: 13.75px;">AOP</a> <a href="/blog/tags/DB/" style="font-size: 13px;">DB</a> <a href="/blog/tags/JDK/" style="font-size: 13.5px;">JDK</a> <a href="/blog/tags/JVM/" style="font-size: 13.5px;">JVM</a> <a href="/blog/tags/Kotlin/" style="font-size: 13px;">Kotlin</a> <a href="/blog/tags/Log/" style="font-size: 13px;">Log</a> <a href="/blog/tags/MVC/" style="font-size: 13px;">MVC</a> <a href="/blog/tags/Spring/" style="font-size: 14px;">Spring</a> <a href="/blog/tags/job/" style="font-size: 13px;">job</a> <a href="/blog/tags/kotlin/" style="font-size: 13px;">kotlin</a> <a href="/blog/tags/linux/" style="font-size: 13px;">linux</a> <a href="/blog/tags/plan/" style="font-size: 13px;">plan</a> <a href="/blog/tags/sublime/" style="font-size: 13px;">sublime</a> <a href="/blog/tags/事务/" style="font-size: 13px;">事务</a> <a href="/blog/tags/坑记/" style="font-size: 13px;">坑记</a> <a href="/blog/tags/并发/" style="font-size: 13px;">并发</a> <a href="/blog/tags/集合/" style="font-size: 13.25px;">集合</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">所有文章</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2018/08/">八月 2018</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2018/07/">七月 2018</a><span class="archive-list-count">12</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2018/06/">六月 2018</a><span class="archive-list-count">7</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/技能/">技能</a>
              </p>
              <p class="item-title">
                <a href="/blog/2018/08/08/JAVA对象的两种访问定位方式/" class="title">JAVA对象的两种访问定位方式</a>
              </p>
              <p class="item-date">
                <time datetime="2018-08-08T06:41:32.000Z" itemprop="datePublished">2018年08月08日</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/技能/">技能</a>
              </p>
              <p class="item-title">
                <a href="/blog/2018/08/07/spring-mvc源码阅读-DispatcherServlet/" class="title">spring mvc源码阅读 - DispatcherServlet</a>
              </p>
              <p class="item-date">
                <time datetime="2018-08-07T01:57:38.000Z" itemprop="datePublished">2018年08月07日</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/技能/">技能</a>
              </p>
              <p class="item-title">
                <a href="/blog/2018/07/26/ACID/" class="title">ACID</a>
              </p>
              <p class="item-date">
                <time datetime="2018-07-26T14:24:03.000Z" itemprop="datePublished">2018年07月26日</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/技能/">技能</a>
              </p>
              <p class="item-title">
                <a href="/blog/2018/07/12/Kotlin-的异常/" class="title">Kotlin 的异常</a>
              </p>
              <p class="item-date">
                <time datetime="2018-07-12T13:42:03.000Z" itemprop="datePublished">2018年07月12日</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/技能/">技能</a>
              </p>
              <p class="item-title">
                <a href="/blog/2018/07/12/Spring-AOP-玩一下异常的流程/" class="title">Spring AOP 玩一下异常的流程</a>
              </p>
              <p class="item-date">
                <time datetime="2018-07-12T13:39:07.000Z" itemprop="datePublished">2018年07月12日</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<main class="main" role="main">
  <div class="content">
  <article id="post-Spring AOP @Before @Around @After 等 advice 的执行顺序" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      Spring AOP @Before @Around @After 等 advice 的执行顺序
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/2018/07/05/Spring AOP @Before @Around @After 等 advice 的执行顺序/" class="article-date">
	  <time datetime="2018-07-05T10:50:08.000Z" itemprop="datePublished">2018年07月05日</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/blog/categories/技能/">技能</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/blog/tags/AOP/">AOP</a>, <a class="article-tag-link" href="/blog/tags/Spring/">Spring</a>
  </span>


        

        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/2018/07/05/Spring AOP @Before @Around @After 等 advice 的执行顺序/#comments" class="article-comment-link">评论</a></span>
        
      </div>
    </div>
    <div class="article-entry markdown-body" itemprop="articleBody">
      
        <blockquote>
<p>author:rainbow702<br>url:<a href="https://blog.csdn.net/rainbow702/article/details/52185827" target="_blank" rel="noopener">https://blog.csdn.net/rainbow702/article/details/52185827</a></p>
</blockquote>
<p>用过spring框架进行开发的人，多多少少会使用过它的AOP功能，都知道有@Before、@Around和@After等advice。最近，为了实现项目中的输出日志和权限控制这两个需求，我也使用到了AOP功能。我使用到了@Before、@Around这两个advice。但在，使用过程中，却对它们的执行顺序并不清楚。为了弄清楚在不同情况下，这些advice到底是以怎么样的一个顺序进行执行的，我作了个测试，在此将其记录下来，以供以后查看。</p>
<h2 id="前提"><a href="#前提" class="headerlink" title="前提"></a>前提</h2><ul>
<li>对于AOP相关类(aspect、pointcut等)的概念，本文不作说明。</li>
<li>对于如何让spring框架扫描到AOP，本文也不作说明。</li>
</ul>
<h2 id="情况一-一个方法只被一个Aspect类拦截"><a href="#情况一-一个方法只被一个Aspect类拦截" class="headerlink" title="情况一: 一个方法只被一个Aspect类拦截"></a>情况一: 一个方法只被一个Aspect类拦截</h2><p>当一个方法只被一个Aspect拦截时，这个Aspect中的不同advice是按照怎样的顺序进行执行的呢？请看:</p>
<h4 id="添加-PointCut类"><a href="#添加-PointCut类" class="headerlink" title="添加 PointCut类"></a>添加 PointCut类</h4><p>该pointcut用来拦截test包下的所有类中的所有方法。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">package test;</span><br><span class="line"></span><br><span class="line">import org.aspectj.lang.annotation.Pointcut;</span><br><span class="line"></span><br><span class="line">public class PointCuts &#123;</span><br><span class="line">    @Pointcut(value = &quot;within(test.*)&quot;)</span><br><span class="line">    public void aopDemo() &#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h4 id="添加Aspect类"><a href="#添加Aspect类" class="headerlink" title="添加Aspect类"></a>添加Aspect类</h4><p>该类中的advice将会用到上面的pointcut，使用方法请看各个advice的value属性。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">package test;</span><br><span class="line"></span><br><span class="line">import org.aspectj.lang.JoinPoint;</span><br><span class="line">import org.aspectj.lang.ProceedingJoinPoint;</span><br><span class="line">import org.aspectj.lang.annotation.*;</span><br><span class="line">import org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line">@Component</span><br><span class="line">@Aspect</span><br><span class="line">public class Aspect1 &#123;</span><br><span class="line"></span><br><span class="line">    @Before(value = &quot;test.PointCuts.aopDemo()&quot;)</span><br><span class="line">    public void before(JoinPoint joinPoint) &#123;</span><br><span class="line">        System.out.println(&quot;[Aspect1] before advise&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Around(value = &quot;test.PointCuts.aopDemo()&quot;)</span><br><span class="line">    public void around(ProceedingJoinPoint pjp) throws  Throwable&#123;</span><br><span class="line">        System.out.println(&quot;[Aspect1] around advise 1&quot;);</span><br><span class="line">        pjp.proceed();</span><br><span class="line">        System.out.println(&quot;[Aspect1] around advise2&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @AfterReturning(value = &quot;test.PointCuts.aopDemo()&quot;)</span><br><span class="line">    public void afterReturning(JoinPoint joinPoint) &#123;</span><br><span class="line">        System.out.println(&quot;[Aspect1] afterReturning advise&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @AfterThrowing(value = &quot;test.PointCuts.aopDemo()&quot;)</span><br><span class="line">    public void afterThrowing(JoinPoint joinPoint) &#123;</span><br><span class="line">        System.out.println(&quot;[Aspect1] afterThrowing advise&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @After(value = &quot;test.PointCuts.aopDemo()&quot;)</span><br><span class="line">    public void after(JoinPoint joinPoint) &#123;</span><br><span class="line">        System.out.println(&quot;[Aspect1] after advise&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h4 id="添加测试用Controller"><a href="#添加测试用Controller" class="headerlink" title="添加测试用Controller"></a>添加测试用Controller</h4><p>添加一个用于测试的controller，这个controller中只有一个方法，但是它会根据参数值的不同，会作出不同的处理：一种是正常返回一个对象，一种是抛出异常(因为我们要测试@AfterThrowing这个advice)</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">package test;</span><br><span class="line"></span><br><span class="line">import test.exception.TestException;</span><br><span class="line">import org.springframework.http.HttpStatus;</span><br><span class="line">import org.springframework.web.bind.annotation.*;</span><br><span class="line"></span><br><span class="line">@RestController</span><br><span class="line">@RequestMapping(value = &quot;/aop&quot;)</span><br><span class="line">public class AopTestController &#123;</span><br><span class="line"></span><br><span class="line">    @ResponseStatus(HttpStatus.OK)</span><br><span class="line">    @RequestMapping(value = &quot;/test&quot;, method = RequestMethod.GET)</span><br><span class="line">    public Result test(@RequestParam boolean throwException) &#123;</span><br><span class="line">        // case 1</span><br><span class="line">        if (throwException) &#123;</span><br><span class="line">            System.out.println(&quot;throw an exception&quot;);</span><br><span class="line">            throw new TestException(&quot;mock a server exception&quot;);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        // case 2</span><br><span class="line">        System.out.println(&quot;test OK&quot;);</span><br><span class="line">        return new Result() &#123;&#123;</span><br><span class="line">            this.setId(111);</span><br><span class="line">            this.setName(&quot;mock a Result&quot;);</span><br><span class="line">        &#125;&#125;;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public static class Result &#123;</span><br><span class="line">        private int id;</span><br><span class="line">        private String name;</span><br><span class="line"></span><br><span class="line">        public int getId() &#123;</span><br><span class="line">            return id;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        public void setId(int id) &#123;</span><br><span class="line">            this.id = id;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        public String getName() &#123;</span><br><span class="line">            return name;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        public void setName(String name) &#123;</span><br><span class="line">            this.name = name;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="测试-正常情况"><a href="#测试-正常情况" class="headerlink" title="测试 正常情况"></a>测试 正常情况</h4><p>在浏览器直接输入以下的URL，回车：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://192.168.142.8:7070/aoptest/v1/aop/test?throwException=false</span><br></pre></td></tr></table></figure></p>
<p>我们会看到输出的结果是：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[Aspect1] around advise 1</span><br><span class="line">[Aspect1] before advise</span><br><span class="line">test OK</span><br><span class="line">[Aspect1] around advise2</span><br><span class="line">[Aspect1] after advise</span><br><span class="line">[Aspect1] afterReturning advise</span><br></pre></td></tr></table></figure></p>
<h4 id="测试-异常情况"><a href="#测试-异常情况" class="headerlink" title="测试 异常情况"></a>测试 异常情况</h4><p>在浏览器中直接输入以下的URL，回车：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://192.168.142.8:7070/aoptest/v1/aop/test?throwException=true</span><br></pre></td></tr></table></figure></p>
<p>我们会看到输出的结果是：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[Aspect1] around advise 1</span><br><span class="line">[Aspect1] before advise</span><br><span class="line">throw an exception</span><br><span class="line">[Aspect1] after advise</span><br><span class="line">[Aspect1] afterThrowing advise</span><br></pre></td></tr></table></figure></p>
<h4 id="结论"><a href="#结论" class="headerlink" title="结论"></a>结论</h4><p>在一个方法只被一个aspect类拦截时，aspect类内部的 advice 将按照以下的顺序进行执行：</p>
<p>正常情况：<br><img src="http://pba56k9nr.bkt.clouddn.com/AOP%E9%A1%BA%E5%BA%8F%E6%AD%A3%E5%B8%B8%E6%83%85%E5%86%B5.png" alt="正常情况"></p>
<hr>
<p>异常情况：<br><img src="http://pba56k9nr.bkt.clouddn.com/AOP%E9%A1%BA%E5%BA%8F%E5%BC%82%E5%B8%B8%E6%83%85%E5%86%B5.png" alt="异常情况"></p>
<hr>
<h2 id="情况二-同一个方法被多个Aspect类拦截"><a href="#情况二-同一个方法被多个Aspect类拦截" class="headerlink" title="情况二: 同一个方法被多个Aspect类拦截"></a>情况二: 同一个方法被多个Aspect类拦截</h2><p>此处举例为被两个aspect类拦截。</p>
<p>有些情况下，对于两个不同的aspect类，不管它们的advice使用的是同一个pointcut，还是不同的pointcut，都有可能导致同一个方法被多个aspect类拦截。那么，在这种情况下，这多个Aspect类中的advice又是按照怎样的顺序进行执行的呢？请看:</p>
<h4 id="pointcut类保持不变"><a href="#pointcut类保持不变" class="headerlink" title="pointcut类保持不变"></a>pointcut类保持不变</h4><p>添加一个新的aspect类<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">package test;</span><br><span class="line"></span><br><span class="line">import org.aspectj.lang.JoinPoint;</span><br><span class="line">import org.aspectj.lang.ProceedingJoinPoint;</span><br><span class="line">import org.aspectj.lang.annotation.*;</span><br><span class="line">import org.springframework.stereotype.Component;</span><br><span class="line"></span><br><span class="line">@Component</span><br><span class="line">@Aspect</span><br><span class="line">public class Aspect2 &#123;</span><br><span class="line"></span><br><span class="line">    @Before(value = &quot;test.PointCuts.aopDemo()&quot;)</span><br><span class="line">    public void before(JoinPoint joinPoint) &#123;</span><br><span class="line">        System.out.println(&quot;[Aspect2] before advise&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @Around(value = &quot;test.PointCuts.aopDemo()&quot;)</span><br><span class="line">    public void around(ProceedingJoinPoint pjp) throws Throwable&#123;</span><br><span class="line">        System.out.println(&quot;[Aspect2] around advise 1&quot;);</span><br><span class="line">        pjp.proceed();</span><br><span class="line">        System.out.println(&quot;[Aspect2] around advise2&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @AfterReturning(value = &quot;test.PointCuts.aopDemo()&quot;)</span><br><span class="line">    public void afterReturning(JoinPoint joinPoint) &#123;</span><br><span class="line">        System.out.println(&quot;[Aspect2] afterReturning advise&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @AfterThrowing(value = &quot;test.PointCuts.aopDemo()&quot;)</span><br><span class="line">    public void afterThrowing(JoinPoint joinPoint) &#123;</span><br><span class="line">        System.out.println(&quot;[Aspect2] afterThrowing advise&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @After(value = &quot;test.PointCuts.aopDemo()&quot;)</span><br><span class="line">    public void after(JoinPoint joinPoint) &#123;</span><br><span class="line">        System.out.println(&quot;[Aspect2] after advise&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h4 id="测试用Controller也不变"><a href="#测试用Controller也不变" class="headerlink" title="测试用Controller也不变"></a>测试用Controller也不变</h4><p>还是使用上面的那个Controller。但是现在 aspect1 和 aspect2 都会拦截该controller中的方法。</p>
<p>下面继续进行测试！</p>
<h4 id="测试-正常情况-1"><a href="#测试-正常情况-1" class="headerlink" title="测试 正常情况"></a>测试 正常情况</h4><p>在浏览器直接输入以下的URL，回车：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://192.168.142.8:7070/aoptest/v1/aop/test?throwException=false</span><br></pre></td></tr></table></figure></p>
<p>我们会看到输出的结果是：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[Aspect2] around advise 1</span><br><span class="line">[Aspect2] before advise</span><br><span class="line">[Aspect1] around advise 1</span><br><span class="line">[Aspect1] before advise</span><br><span class="line">test OK</span><br><span class="line">[Aspect1] around advise2</span><br><span class="line">[Aspect1] after advise</span><br><span class="line">[Aspect1] afterReturning advise</span><br><span class="line">[Aspect2] around advise2</span><br><span class="line">[Aspect2] after advise</span><br><span class="line">[Aspect2] afterReturning advise</span><br></pre></td></tr></table></figure></p>
<p>但是这个时候，我<strong>不能</strong>下定论说 aspect2 肯定就比 aspect1 先执行。<br>不信？你把服务务器重新启动一下，再试试，说不定你就会看到如下的执行结果：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[Aspect1] around advise 1</span><br><span class="line">[Aspect1] before advise</span><br><span class="line">[Aspect2] around advise 1</span><br><span class="line">[Aspect2] before advise</span><br><span class="line">test OK</span><br><span class="line">[Aspect2] around advise2</span><br><span class="line">[Aspect2] after advise</span><br><span class="line">[Aspect2] afterReturning advise</span><br><span class="line">[Aspect1] around advise2</span><br><span class="line">[Aspect1] after advise</span><br><span class="line">[Aspect1] afterReturning advise</span><br></pre></td></tr></table></figure></p>
<p>也就是说，这种情况下， aspect1 和 aspect2 的执行顺序是未知的。那怎么解决呢？不急，下面会给出解决方案。</p>
<h4 id="测试-异常情况-1"><a href="#测试-异常情况-1" class="headerlink" title="测试 异常情况"></a>测试 异常情况</h4><p>在浏览器中直接输入以下的URL，回车：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://192.168.142.8:7070/aoptest/v1/aop/test?throwException=true</span><br></pre></td></tr></table></figure></p>
<p>我们会看到输出的结果是：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[Aspect2] around advise 1</span><br><span class="line">[Aspect2] before advise</span><br><span class="line">[Aspect1] around advise 1</span><br><span class="line">[Aspect1] before advise</span><br><span class="line">throw an exception</span><br><span class="line">[Aspect1] after advise</span><br><span class="line">[Aspect1] afterThrowing advise</span><br><span class="line">[Aspect2] after advise</span><br><span class="line">[Aspect2] afterThrowing advise</span><br></pre></td></tr></table></figure></p>
<p>同样地，如果把服务器重启，然后再测试的话，就可能会看到如下的结果：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[Aspect1] around advise 1</span><br><span class="line">[Aspect1] before advise</span><br><span class="line">[Aspect2] around advise 1</span><br><span class="line">[Aspect2] before advise</span><br><span class="line">throw an exception</span><br><span class="line">[Aspect2] after advise</span><br><span class="line">[Aspect2] afterThrowing advise</span><br><span class="line">[Aspect1] after advise</span><br><span class="line">[Aspect1] afterThrowing advise</span><br></pre></td></tr></table></figure></p>
<p>也就是说，同样地，异常情况下， aspect1 和 aspect2 的执行顺序也是未定的。</p>
<h4 id="那么在-情况二-下，如何指定每个-aspect-的执行顺序呢？"><a href="#那么在-情况二-下，如何指定每个-aspect-的执行顺序呢？" class="headerlink" title="那么在 情况二 下，如何指定每个 aspect 的执行顺序呢？"></a>那么在 情况二 下，如何指定每个 aspect 的执行顺序呢？</h4><p>方法有两种：</p>
<blockquote>
<p>实现org.springframework.core.Ordered接口，实现它的getOrder()方法<br>给aspect添加@Order注解，该注解全称为：org.springframework.core.annotation.Order<br>不管采用上面的哪种方法，都是<strong>值越小的 aspect 越先执行。</strong><br>比如，我们为 apsect1 和 aspect2 分别添加 @Order 注解，如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">@Order(5)</span><br><span class="line">@Component</span><br><span class="line">@Aspect</span><br><span class="line">public class Aspect1 &#123;</span><br><span class="line">    // ...</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">@Order(6)</span><br><span class="line">@Component</span><br><span class="line">@Aspect</span><br><span class="line">public class Aspect2 &#123;</span><br><span class="line">    // ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
</blockquote>
<p>这样修改之后，可保证不管在任何情况下， aspect1 中的 advice 总是比 aspect2 中的 advice 先执行。如下图所示：<br><img src="http://pba56k9nr.bkt.clouddn.com/AOP%E5%A4%9A%E5%88%87%E7%82%B9%E6%8B%A6%E6%88%AA%E9%A1%BA%E5%BA%8F.png" alt="多切点顺序"></p>
<hr>
<h2 id="注意点"><a href="#注意点" class="headerlink" title="注意点"></a>注意点</h2><ul>
<li><p>如果在同一个 aspect 类中，针对同一个 pointcut，定义了两个相同的 advice(比如，定义了两个 @Before)，那么这两个 advice 的执行顺序是无法确定的，哪怕你给这两个 advice 添加了 @Order 这个注解，也不行。这点切记。</p>
</li>
<li><p>对于@Around这个advice，不管它有没有返回值，但是必须要方法内部，调用一下 pjp.proceed();否则，Controller 中的接口将没有机会被执行，从而也导致了 @Before这个advice不会被触发。比如，我们假设正常情况下，执行顺序为”aspect2 -&gt; apsect1 -&gt; controller”，如果，我们把 aspect1中的@Around中的 pjp.proceed();给删掉，那么，我们看到的输出结果将是：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[Aspect2] around advise 1</span><br><span class="line">[Aspect2] before advise</span><br><span class="line">[Aspect1] around advise 1</span><br><span class="line">[Aspect1] around advise2</span><br><span class="line">[Aspect1] after advise</span><br><span class="line">[Aspect1] afterReturning advise</span><br><span class="line">[Aspect2] around advise2</span><br><span class="line">[Aspect2] after advise</span><br><span class="line">[Aspect2] afterReturning advise</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>从结果可以发现， Controller 中的 接口 未被执行，aspect1 中的 @Before advice 也未被执行。</p>
<h2 id="参考资料"><a href="#参考资料" class="headerlink" title="参考资料"></a>参考资料</h2><p>Spring 4.3.2.RELEASE 官方资料：<a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/" target="_blank" rel="noopener">http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/</a><br>其中，AOP的执行顺序章节为：<a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#aop-ataspectj-advice-ordering" target="_blank" rel="noopener">http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#aop-ataspectj-advice-ordering</a><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">Advice ordering</span><br><span class="line"></span><br><span class="line">What happens when multiple pieces of advice all want to run at the same join point? </span><br><span class="line">Spring AOP follows the same precedence rules as AspectJ to determine the order of advice execution. </span><br><span class="line">The highest precedence advice runs first &quot;on the way in&quot; (so given two pieces of before advice, the one with highest precedence runs first).</span><br><span class="line">&quot;On the way out&quot; from a join point, the highest precedence advice runs last (so given two pieces of after advice, the one with the highest precedence will run second).</span><br><span class="line"></span><br><span class="line">When two pieces of advice defined in different aspects both need to run at the same join point,</span><br><span class="line">unless you specify otherwise the order of execution is undefined. </span><br><span class="line">You can control the order of execution by specifying precedence.</span><br><span class="line">This is done in the normal Spring way by either implementing the org.springframework.core.Ordered interface in the aspect class or annotating it with the Order annotation. </span><br><span class="line">Given two aspects, the aspect returning the lower value from Ordered.getValue() (or the annotation value) has the higher precedence.</span><br><span class="line"></span><br><span class="line">When two pieces of advice defined in the same aspect both need to run at the same join point, </span><br><span class="line">the ordering is undefined (since there is no way to retrieve the declaration order via reflection for javac-compiled classes). </span><br><span class="line">Consider collapsing such advice methods into one advice method per join point in each aspect class, </span><br><span class="line">or refactor the pieces of advice into separate aspect classes - which can be ordered at the aspect level.</span><br></pre></td></tr></table></figure></p>

      
    </div>
    <div class="article-footer">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="https://ji-song.gitee.io/blog/2018/07/05/Spring AOP @Before @Around @After 等 advice 的执行顺序/" title="Spring AOP @Before @Around @After 等 advice 的执行顺序" target="_blank" rel="external">https://ji-song.gitee.io/blog/2018/07/05/Spring AOP @Before @Around @After 等 advice 的执行顺序/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://gitee.com/ji-song" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/avatar.jpeg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://gitee.com/ji-song" target="_blank"><span class="text-dark">JiSong</span><small class="ml-1x">Java Coder</small></a></h3>
        <div>个人简介。</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/2018/07/05/spring-boot-配置elastic-job-分片任务/" title="spring-boot 配置elastic-job 分片任务"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/2018/07/04/坑记：springMVC取post参数/" title="坑记：springMVC取post参数"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
  </ul>
  
  
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-fancy btn-donate pop-onhover bg-gradient-warning" data-toggle="modal" data-target="#donateModal"><span>赏</span></button>
  <!-- <div class="wave-icon wave-icon-danger btn-donate" data-toggle="modal" data-target="#donateModal">
    <div class="wave-circle"><span class="icon"><i class="icon icon-bill"></i></span></div>
  </div> -->
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,facebook,twitter" data-mobile-sites="weibo,qq,qzone"></div>
    
  </div>
  </div>
</nav>
  
<!-- Modal -->
<div class="modal modal-center modal-small modal-xs-full fade" id="donateModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content donate">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <div class="modal-body">
        <div class="donate-box">
          <div class="donate-head">
            <p>感谢您的支持，我会继续努力的!</p>
          </div>
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane fade active in" id="alipay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/alipayimg.jpg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开支付宝扫一扫，即可进行扫码打赏哦</p>
            </div>
            <div role="tabpanel" class="tab-pane fade" id="wechatpay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/wechatpayimg.jpg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开微信扫一扫，即可进行扫码打赏哦</p>
            </div>
          </div>
          <div class="donate-footer">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <li role="presentation" class="active">
                <a href="#alipay" id="alipay-tab" role="tab" data-toggle="tab" aria-controls="alipay" aria-expanded="true"><i class="icon icon-alipay"></i> 支付宝</a>
              </li>
              <li role="presentation" class="">
                <a href="#wechatpay" role="tab" id="wechatpay-tab" data-toggle="tab" aria-controls="wechatpay" aria-expanded="false"><i class="icon icon-wepay"></i> 微信支付</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>



</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://gitee.com/ji-song" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>
<script src="/blog/js/plugin.min.js"></script>
<script src="/blog/js/application.js"></script>
  
    
    
    
        <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/blog/js/insight.js"></script>
    
    
    
        


    
    
        
    
    



</body>
</html>